package com.inspur.cmis.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.inspur.cmis.pojo.User;
import com.inspur.cmis.service.UserService;

@Controller
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/loginController")
	public ModelAndView login(User user,HttpSession session){
		ModelAndView mv=new ModelAndView();
		//用户登陆
		User checkUser=userService.getUser(user);
		//用户登陆成功
		if(null!=checkUser){
			mv.addObject("success","恭喜您，登陆成功");
			session.setAttribute("user", checkUser);//暂存登陆后的用户信息
			mv.setViewName("main.jsp");
		//登陆失败
		}else{
			mv.addObject("error","用户名或密码错误，请重填");
			mv.setViewName("login.jsp");
		}
		return mv;
	}

}
